Replace all uses of gmtime(foo) + get_tz_offset() with a call to mkgmtime
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 28 Jun 2005 17:20:27 +0000 (17:20 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 28 Jun 2005 17:20:27 +0000 (17:20 +0000)
which converts a tmstruct in UTC to a time_t.

gpsbabel/coastexp.c
gpsbabel/gpx.c
gpsbabel/hiketech.c
gpsbabel/igc.c
gpsbabel/magproto.c
gpsbabel/nmea.c
gpsbabel/pathaway.c
gpsbabel/pcx.c
gpsbabel/psitrex.c
gpsbabel/util.c
gpsbabel/vitosmt.c

index faef555f54068dec812f034de384ea44e629cb93..81b2a19ebc1e340841bda7923b0b7f2f8bcf8545 100755 (executable)
@@ -268,7 +268,7 @@ ce_cdata(void *dta, const XML_Char *s, int len)
                                        strncpy(secString, currentMark->created+13, 2);
                                        secString[2] = '\0';
                                        t.tm_sec = atoi(secString);
-                                       currentMark->wp->creation_time = mktime(&t) + get_tz_offset();
+                                       currentMark->wp->creation_time = mkgmtime(&t);
                                }
                        }
                        else if (inRoute) {
index 178403c9c49195ec00b07742f79267373b41a4c9..1f05085851ae9bcdae971a4a73506aacc10bcf42 100644 (file)
@@ -614,8 +614,7 @@ xml_parse_time( const char *cdatastr )
        tm.tm_year -= 1900;
        tm.tm_isdst = 0;
        
-       rv = mktime(&tm) + get_tz_offset() - off_sign*off_hr*3600 - 
-               off_sign*off_min*60;
+       rv = mkgmtime(&tm) - off_sign*off_hr*3600 - off_sign*off_min*60;
        
         xfree(timestr);
        
index a1d0264858bab0082eb7f0344f450b911e6d4847..b95828246c540636813aff3d960a4f8035b035e2 100644 (file)
@@ -244,7 +244,7 @@ void        ht_trk_utc(const char *args, const char **unused)
         tm.tm_year -= 1900;
         tm.tm_isdst = 0;
 
-        utc = mktime(&tm) + get_tz_offset() ;
+        utc = mkgmtime(&tm);
 
        wpt_tmp->creation_time = utc;
 }
index 188e7d3783ee84dd1eb02bc159575145fc9b4543..1874e4edb999fed1005bb7f10d77e81452602fcf 100644 (file)
@@ -165,7 +165,7 @@ static void igc_task_rec(const char *rec)
            tm.tm_year += 100;
        }
        tm.tm_isdst = 0;
-       creation = mktime(&tm) + get_tz_offset();
+       creation = mkgmtime(&tm);
 
        // Create a route to store the task data in.
        rte_head = route_head_alloc();
@@ -297,7 +297,7 @@ static void data_read(void)
                    tm.tm_year += 100;
                }
                tm.tm_isdst = 0;
-               date = mktime(&tm) + get_tz_offset();
+               date = mkgmtime(&tm);
            } else {
                // Store other header data in the track descriptions
                if (strlen(trk_desc) < MAXDESCLEN) {
index 48151b532ad93dc0d0ee7ea8da610c69a876f04e..4e0898b0637c39f2a050d5edf01f161e6a5f3a32 100644 (file)
@@ -915,7 +915,7 @@ mag_trkparse(char *trkmsg)
        dmy = dmy / 100;
        tm.tm_mday = dmy % 100; 
 
-       waypt->creation_time = mktime(&tm) + get_tz_offset();
+       waypt->creation_time = mkgmtime(&tm);
        waypt->centiseconds = fracsecs;
 
        if (latdir == 'S') latdeg = -latdeg;
index 30d9ccf3ab1c7f215747e1c56fc17126558ac160..5b00d7b75a1eee6c5d2981f5edbaf86e1a2850f6 100644 (file)
@@ -268,7 +268,7 @@ gprmc_parse(char *ibuf)
        tm.tm_mon  = dmy % 100 - 1;
        dmy = dmy / 100;
        tm.tm_mday = dmy;
-       creation_time = mktime(&tm) + get_tz_offset();
+       creation_time = mkgmtime(&tm);
 
        if (posn_type == gpgga)
                return;
@@ -327,7 +327,7 @@ gpzda_parse(char *ibuf)
        tm.tm_mday = dd;
        tm.tm_mon  = mm - 1;
        tm.tm_year = yy - 1900;
-       creation_time = mktime(&tm) + get_tz_offset();
+       creation_time = mkgmtime(&tm);
 }
 
 static void
@@ -338,7 +338,7 @@ nmea_read(void)
        int ckval, ckcmp;
        struct tm tm;
 
-       creation_time = mktime(&tm) + get_tz_offset() + current_time();
+       creation_time = mkgmtime(&tm) + current_time();
 
        while (fgets(ibuf, sizeof(ibuf), file_in)) {
                ck = strrchr(ibuf, '*');
index ea1fd2a1d6d0e9125c1f5a000b120e8d99f8124a..fd779078c165fd2512f5476d327de697c0a2e226 100644 (file)
@@ -370,7 +370,7 @@ static int ppdb_read_wpt(const struct pdb *pdb_in, const struct pdb_record *pdb_
                            {
                                tm.tm_year -= 1900;
                                tm.tm_mon--;
-                               wpt_tmp->creation_time = mktime(&tm) + get_tz_offset();
+                               wpt_tmp->creation_time = mkgmtime(&tm);
                            }
                            break;
                        case 5:
index fb4f87276feafa6ddeea574d6d5c4a8ba2719b66..1bafae196b99952c28b53165adac12b0aa5899d5 100644 (file)
@@ -149,7 +149,7 @@ data_read(void)
                        tm.tm_mon = month_lookup(month);
                        tm.tm_year = atoi(date + 7) + 100;
                        wpt_tmp = waypt_new();
-                       wpt_tmp->creation_time = mktime(&tm) + get_tz_offset();
+                       wpt_tmp->creation_time = mkgmtime(&tm);
                        wpt_tmp->latitude = lat;
                        wpt_tmp->longitude = lon;
                        wpt_tmp->altitude = alt;
index 89ab8dd9aaa4552f846aaec40e997b7ac4e83984..4b86b6ca147be1e67cca2898efb85a3ac4340ef4 100755 (executable)
@@ -570,7 +570,7 @@ psit_track_r(FILE *psit_file, route_head **trk)
                                        &(tmTime.tm_sec));
 
                        tmTime.tm_isdst = 0;
-                       dateTime = mktime(&tmTime) + get_tz_offset();
+                       dateTime = mkgmtime(&tmTime);
 
                        psit_getToken(psit_file,psit_current_token,sizeof(psit_current_token), whitespace);
 
index d3a958284a667d245463539d30f76a53ef3759ef..cb9a689df10d75c546fad3d29cf5e4aa75f851d0 100644 (file)
@@ -477,6 +477,7 @@ si_round( double d )
 /*
  *  Return a time_t suitable for adding to a time_t that is in GMT to
  *  make it a local time.
+ *  Obsolete: to use mkgmtime instead.
  */
 signed int 
 get_tz_offset(void)
@@ -491,6 +492,54 @@ get_tz_offset(void)
        }
 }
 
+/*
+       mkgmtime -- convert tm struct in UTC to time_t
+
+       works just like mktime but without all the mucking
+       around with timezones and daylight savings
+
+       obsoletes get_tz_offset()
+
+       Borrowed from lynx GPL source code
+       http://lynx.isc.org/release/lynx2-8-5/src/mktime.c
+
+       Written by Philippe De Muyter <phdm@macqel.be>.
+*/
+
+time_t
+mkgmtime(struct tm *t)
+{
+       short  month, year;
+       time_t result;
+       static int      m_to_d[12] =
+               {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
+
+       month = t->tm_mon;
+       year = t->tm_year + month / 12 + 1900;
+       month %= 12;
+       if (month < 0)
+       {
+               year -= 1;
+               month += 12;
+       }
+       result = (year - 1970) * 365 + m_to_d[month];
+       if (month <= 1)
+               year -= 1;
+       result += (year - 1968) / 4;
+       result -= (year - 1900) / 100;
+       result += (year - 1600) / 400;
+       result += t->tm_mday;
+       result -= 1;
+       result *= 24;
+       result += t->tm_hour;
+       result *= 60;
+       result += t->tm_min;
+       result *= 60;
+       result += t->tm_sec;
+       return(result);
+}
+
+
 /*
  * A wrapper for time(2) that allows us to "freeze" time for testing.
  */
index 9f77dd4c162f5d580c385ae692e307782d59f1cc..ceaf9be8762212fadeecf8b8c01666ff2d145f0d 100644 (file)
@@ -162,7 +162,7 @@ vitosmt_read(void)
                tmStruct.tm_sec         =(int)floor(seconds);
                tmStruct.tm_isdst       =-1;
 
-               wpt_tmp->creation_time = mktime(&tmStruct) + get_tz_offset();
+               wpt_tmp->creation_time = mkgmtime(&tmStruct);
                wpt_tmp->centiseconds = fmod(100*seconds+0.5,100);
        
                snprintf(shortname, sizeof shortname-1 , "WP%04d", ++serial);